package com.example.spinning.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.spinning.bean.PaginationResult;
import com.example.spinning.bean.YearlyReport;
import com.example.spinning.mapper.YearlyReportMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional
public class YearlyReportService {
    @Autowired
    YearlyReportMapper yearlyReportMapper;



    //增加操作
    public int addNewYearlyReport(YearlyReport yearlyReport) {
        //monthlyReport.setDate(new Timestamp(System.currentTimeMillis()));
        return yearlyReportMapper.addNewYearlyReport(yearlyReport);
    }

    //删除操作
    public boolean deleteYearlyReportById(Long[] ids) {
        int result = yearlyReportMapper.deleteYearlyReportById(ids);
        return result == ids.length;
    }
    //查询并分页
//    public PageInfo<YearlyReport> findPage(Integer page, Integer size,String workshop,String year) {
//
//        YearlyReport yearlyReport = new YearlyReport();
//        yearlyReport.setWorkshop(workshop);
//        yearlyReport.setYear(year);
//
//        PageHelper.startPage(page,size);
//        List<YearlyReport> list = yearlyReportMapper.select(yearlyReport);
//        PageInfo<YearlyReport> pageInfo = new PageInfo<>(list);
//
//        return pageInfo;
//    }
    public PaginationResult<YearlyReport> findPage(Integer page, Integer size,String workshop,String year) {

        QueryWrapper<YearlyReport> wrapper = new QueryWrapper();
        if (null != workshop)
            wrapper.eq("workshop", workshop);
        if (null != year)
            wrapper.eq("year", year);

        Page<YearlyReport> pages = new Page<>(page, size);
        yearlyReportMapper.selectPage(pages, wrapper);
        int total = yearlyReportMapper.selectCount(wrapper);
        List<YearlyReport> list = pages.getRecords();

        PaginationResult<YearlyReport> pr = new PaginationResult<>();
        pr.setTotal(total);
        pr.setList(list);
        return pr;
    }
    //动态修改
    public int  updateCategoryById(YearlyReport yearlyReport){
        int result = yearlyReportMapper.updateById(yearlyReport);
        return result;
    }


}




